package zlx.springcloud.controller;


import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zlx.springcloud.service.OderHystrixService;


import javax.annotation.Resource;

@RestController
//@DefaultProperties(defaultFallback = "oder_Global_FallbackMethod")
public class OderHystrixController {
    @Resource
    private OderHystrixService OderHystrixService;

//    @HystrixCommand
    @RequestMapping(value = "/cusmer/payment/hystrix/ok/{id}")
    public String  paymentHystrix_OK(@PathVariable("id") Integer id){
       return OderHystrixService.paymentHystrix_OK(id);
    }
    @RequestMapping(value = "/cusmer/payment/hystrix/timeout/{id}")
    //服务降级的方法
//    @HystrixCommand(fallbackMethod = "paymentInfo_TimeoutHandler",commandProperties = {
//            //设置响应超时峰值
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3500")
//    })
    @HystrixCommand
    public String  paymentHystrix_timeout(@PathVariable("id") Integer id){
//        int i=10/0;
        return OderHystrixService.paymentHystrix_timeout(id);
    }
    public String  paymentInfo_TimeoutHandler(@PathVariable("id") Integer id){
        return "支付时间超时或系统繁忙，请稍后再试！";
    }
    //这是全局fallback方法
    public String  oder_Global_FallbackMethod(){
        return "Global异常处理信息，请稍后再试!!";
    }
}
